package com.cjq.utils;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Data;
import lombok.experimental.Accessors;


/**
 * @author junqiancai@foxmail.com
 * @since 2021/6/10 22:38
 */
@Data
@Accessors(chain = true)
public class Result{

    private Integer code; // 200是正常，非200表示异常
    private String msg;
    private Object data;

    public static final Integer SUCCESS = 200;      //正常请求成功
    public static final Integer CREATE = 201;      //post添加数据成功
    public static final Integer NO_CONTENT = 204;      //请求成功但是没有返回数据
    public static final Integer Params_Error = 400; //前端参数错误
    public static final Integer NOT_AUTH = 401;     //没认证或认证失败
    public static final Integer NOT_PERMIT = 403;   //没权限
    public static final Integer Server_Error = 500; //服务器处理错误

    public static Result succeed(Integer code) {
        Result r = new Result();
        return r.setCode(code);
    }
    public static Result succeed(Integer code, String msg) {
        return succeed(code, msg, null);
    }
    public static Result succeed(String msg, Object data) {
        return succeed(SUCCESS, msg, data);
    }
    public static Result succeed(Integer code, String msg, Object data) {
        Result r = new Result();
        return r.setCode(code).setMsg(msg).setData(data);
    }

    public static Result fail(Integer code) {
        Result r = new Result();
        return r.setCode(code);
    }
    public static Result fail(Integer code,String msg) {
        return fail(code, msg, null);
    }
    public static Result fail(Integer code, String msg, Object data) {
        Result r = new Result();
        return r.setCode(code).setMsg(msg).setData(data);
    }
}